import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"

enum Api {
  page = "/infra-service/wxAccount/pageAccount",
  list = "/infra-service/wxAccount/listAccount",
  get = "/infra-service/wxAccount/getAccount",
  save = "/infra-service/wxAccount/saveAccount",
  edit = "/infra-service/wxAccount/updateAccount",
  delete = "/infra-service/wxAccount/deleteAccount",
  deleteBatch = "/infra-service/wxAccount/batchDeleteAccount",
  exportXls = "/infra-service/wxAccount/exportXls",
  importExcel = "/infra-service/wxAccount/importExcel",
}
/**
 * 导出api
 */
export const getExportUrl = Api.exportXls
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel
/**
 * 列表
 * @param params
 */
export const pageMpAccount = (params) => defHttp.get({ url: Api.page, params })

export const listMpAccount = () => defHttp.get({ url: Api.list, params: {} })

export const getMpAccount = (params) => defHttp.get({ url: Api.get, params })

/**
 * 删除
 */
export const deleteMpAccount = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

/**
 * 批量删除
 * @param params
 */
export const batchDeleteMpAccount = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdateMpAccount = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save
  return defHttp.post({ url: url, params })
}
